package com.vm.osm.business.service.impl;

import com.vm.osm.business.dao.OsmFailureTypeMapper;
import com.vm.osm.business.dto.rsp.failType.RspFailType;
import com.vm.osm.business.entity.OsmFailureType;
import com.vm.osm.business.service.IFailTureService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by chenzui on 2018/1/26.
 */
@Service
public class FailTureServiceImpl implements IFailTureService {
    @Autowired
    private OsmFailureTypeMapper failureTypeMapper;

    @Override
    public int deleteByPrimaryKey(String id) {
        return failureTypeMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int insert(OsmFailureType record) {
        return failureTypeMapper.insert(record);
    }

    @Override
    public int insertSelective(OsmFailureType record) {
        return failureTypeMapper.insertSelective(record);
    }

    @Override
    public OsmFailureType selectByPrimaryKey(String id) {
        return failureTypeMapper.selectByPrimaryKey(id);
    }

    @Override
    public int updateByPrimaryKeySelective(OsmFailureType record) {
        return failureTypeMapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public int updateByPrimaryKey(OsmFailureType record) {
        return failureTypeMapper.updateByPrimaryKey(record);
    }

    @Override
    public List<RspFailType> findList(String parentId,String enterpriseId) {
        List<RspFailType> firstLevel = failureTypeMapper.findByParentId(parentId,enterpriseId);
        if(!firstLevel.isEmpty()){
            for (RspFailType failType:firstLevel){
                List<RspFailType> secondLevel = failureTypeMapper.findByParentId(failType.getId(),enterpriseId);
                failType.setChildren(secondLevel);
            }
        }
        return firstLevel;
    }
}
